using HotChocolateDemo.OrderService.Host.GraphTypes;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using System.Text;

var builder = WebApplication.CreateBuilder(args);
builder.Services
    .AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options =>
    {
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuer = false,
            ValidateAudience = false,
            ValidateLifetime = false,
            IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Symmetric Security Key")),
        };
    });
builder.Services.AddAuthorization();
builder.Services.AddGraphQLServer()
    //.AddAuthorization()
    .AddQueryType<Query>()
    .AddTypeExtension<OrderResolver>()
    .InitializeOnStartup()
    .PublishSchemaDefinition(c => c
        .SetName("orders")
        .IgnoreType("authorize"));

var app = builder.Build();
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapGraphQL();
app.Run();